
package com.gblw.rjkf.pj.utils;

import cn.hutool.core.util.HexUtil;
import cn.hutool.crypto.BCUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.SM2;


import com.gblw.rjkf.pj.utils.sm.Sm2Util;
import com.gblw.rjkf.pj.utils.sm.Sm3Util;
import com.gblw.rjkf.pj.utils.sm.Sm4Util;
import io.lettuce.core.ScriptOutputType;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@RestController
public class TestController {
    public static void main1(String[] args) {
        //参数
        String str = "{\"test\":\"001\"}";


        Map<String, String> keymap2 = Sm2Util.generator();
        //前端端公钥
        String publicKey2 = keymap2.get("publicKey");
        //前端私钥
        String privateKey2 = keymap2.get("privateKey");

        System.out.println("前端加密参数："+Sm2Util.encrypt(publicKey2,str));
        String cipherText = Sm2Util.encrypt(publicKey2, str);
        String sm23 = Sm3Util.encrypt(publicKey2,cipherText);
        System.out.println("前端加sm3加密："+sm23);
        System.out.println("后端解密获取前端传来的参数："+Sm2Util.decrypt(privateKey2,cipherText));
        String sm233 = Sm3Util.encrypt(publicKey2,cipherText);
        System.out.println("后端加sm3解密比较："+sm233);

        //获取公私钥
        Map<String, String> keymap = Sm2Util.generator();
        //后端公钥
        String publicKey = keymap.get("publicKey");
        //后端私钥
        String privateKey = keymap.get("privateKey");





        if(sm233 .equals(sm23)){
            System.err.println("sm3验证成功");
            String result = Sm2Util.encrypt(publicKey,"sm3验证成功");
            System.err.println("---------后端加密返回成功："+result);
            String sm23q = Sm3Util.encrypt(publicKey,result);
            System.err.println("后端加sm3加密："+sm23q);

            if(sm23q.equals(Sm3Util.encrypt(publicKey,result))){
                System.err.println("数据校验完整");
                String result2 = Sm2Util.decrypt(privateKey,result);
                System.err.println("前端解密返回成功："+result2);
            }



        }
        //


    }

    public static void main(String[] args) {
        String str = "{\"test\":\"001\"}";
        List<String> list = new ArrayList<>();
        for (int i=0;i<1000000;i++){
            list.add(str);

        }
        //获取公私钥
        Map<String, String> keymap = Sm2Util.generator();
        //后端公钥
        String publicKey = keymap.get("publicKey");
        //后端私钥
        String privateKey = keymap.get("privateKey");


        System.out.println(publicKey);
        System.out.println(privateKey);

    }

//04A5F70FB3C64829DC47732FBC442300CA380DA52DD54925CE3D7BDD5E0F60A16F36DDC3EE636CEA1BAF8E2CACD63DBD157C4E04D6C4A6B3F7D0215B93357DC36E  后 公钥
//2A0F962B1D6A412D093525B4855A35B76F7BA5F446494A82CC59648F898A3A6F  后私钥


//042929C3E7DBAD2884080E2ED06FA2CA68501D0C38F664EFD21B9CF3FE064783D795CA8D1F9712305A013A1FD261B37F9B02BCA43D01777B83BA23478BF21F29D4 前公钥
//1266A2A484CAD7974C2E651553D4875610A78A2F1843D36A3001A5A4DE6CA6BC     前私钥
}
